﻿using System;
using System.IO;
using System.Diagnostics;   
namespace MyInstaller
{
	class Search
	{
		public string SearchFile(string DirPath, string FileName)
		{
			string result="";
			DirectoryInfo di = new DirectoryInfo(DirPath);
			FileInfo[] fiArr = di.GetFiles();
			foreach (FileInfo fri in fiArr)
			{
				if(fri.Name.Equals(FileName))
				{
					result=fri.FullName; 
					break;
				}
			}
			if(result.Equals(""))
			{
				DirectoryInfo[] diArr = di.GetDirectories();
				foreach (DirectoryInfo dri in diArr)
				{
					result=SearchFile(dri.FullName,FileName);
					if(!result.Equals("")) break;
				}
			}
			return result;
        }
		
		public void Usage()
		{
			//Minh họa sử dụng
			string Result;
			Result=SearchFile("C:\\Program files","osql.exe");
			if(!Result.Equals(""))	
			{
				//Process.Start(Result,"/U sa /P  /S NDANH /d Pubs /i Remove.sql");
				//Process.Start(Result,"/U sa /P  /S NDANH /d Pubs /i Create.sql");
			}
			else 
			{
				Console.WriteLine("File not found !"); 
			}
		}
	}
}
